package ro.cityprojects.adminloc.entities;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Set;

@Entity
@Table(name = "COUNTY")
public class County implements Serializable {

    @Id
    @Column(name = "COUNTY_ID")
    private Integer countyId;

    @Column(name = "COUNTY_NAME", nullable = false, insertable = true, updatable = true, length = 64, precision = 0)
    private String countyName;

    @Column(name = "REGION_NAME", nullable = true, insertable = true, updatable = true, length = 32, precision = 0)
    private String regionName;

    @OneToMany(fetch = FetchType.LAZY, targetEntity = City.class, mappedBy = "countyByCountyId", cascade = CascadeType.ALL)
    private Set<City> cities;

    public Integer getCountyId() {
        return countyId;
    }

    public void setCountyId(Integer countyId) {
        this.countyId = countyId;
    }

    public String getCountyName() {
        return countyName;
    }

    public void setCountyName(String countyName) {
        this.countyName = countyName;
    }

    public String getRegionName() {
        return regionName;
    }

    public void setRegionName(String regionName) {
        this.regionName = regionName;
    }

    public Set<City> getCities() {
        return cities;
    }

    public void setCities(Set<City> cities) {
        this.cities = cities;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        County county = (County) o;

        if (countyId != null ? !countyId.equals(county.countyId) : county.countyId != null) return false;
        if (countyName != null ? !countyName.equals(county.countyName) : county.countyName != null) return false;
        if (regionName != null ? !regionName.equals(county.regionName) : county.regionName != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = countyId != null ? countyId.hashCode() : 0;
        result = 31 * result + (countyName != null ? countyName.hashCode() : 0);
        result = 31 * result + (regionName != null ? regionName.hashCode() : 0);
        return result;
    }

    @OneToMany(mappedBy = "countyByCountyId")
    private Set<City> citiesByCountyId;

    public Set<City> getCitiesByCountyId() {
        return citiesByCountyId;
    }

    public void setCitiesByCountyId(Set<City> citiesByCountyId) {
        this.citiesByCountyId = citiesByCountyId;
    }
}
